var teamId;
var backURL;
var teamOpponent={};
$(document).ready(function(){
	$.ajaxSettings.async = false;
	$('#header').animate({'top':'0px'},400);
	teamId = args.teamId; //取得id的值
	backURL = args.backURL;
	
	$("#submitBtn").click(function(){
		var strMessage="";
		//检查必填
		if($("input[id='opponentName']").val()==undefined||$.trim($("input[id='opponentName']").val())==""){
			strMessage += "对手名称必填!";
			alert(strMessage);
			return false;
		}
		if($("#contacts").val()==undefined||$.trim($("#contacts").val())==""){
			strMessage += "联系人必填!";
			alert(strMessage);
			return false;
		}
		if($("#contactPhone").val()==undefined||$.trim($("#contactPhone").val())==""){
			strMessage += "联系电话必填!";
			alert(strMessage);
			return false;
		}
		//检查必填结束
		teamOpponentInfo();
		var jsonStr = JSON.stringify(teamOpponent);
		var postData={jsonStr:jsonStr};
		$.post(path+"/soccer/tmTeamOpponentAction!saveTeamOpponent.action",postData, function(data){
			teamOpponent=data.tmTeamOpponent;
			//更新当前编辑比赛的对手
			var teamGame=JSON.parse(sessionStorage.getItem("teamGameEdit"));
			if(teamGame!=null&&teamGame!=undefined){
				teamGame.opponentTeamId=teamOpponent.rowId;
				teamGame.opponentName=teamOpponent.opponentName;
			}
			sessionStorage.setItem("teamGameEdit", JSON.stringify(teamGame));
			goBack();
		},'json');
	});
});
function teamOpponentInfo(){
	if(teamOpponent==null){
		teamOpponent = {};
	}
	teamOpponent.teamId=teamId;
	teamOpponent.opponentOrgId=-1;
	teamOpponent.opponentName=$("input[id='opponentName']").val();
	teamOpponent.contacts=$("input[id='contacts']").val();
	teamOpponent.contactPhone=$("input[id='contactPhone']").val();
	teamOpponent.remark=$("input[id='remark']").val();
}

function goBack(){
	var timestamp = (new Date()).valueOf();
	window.location.href=path+backURL+"?teamId="+teamId+"&timestamp="+timestamp;
}
